package org.nobody.mallb2c.mallmember.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author 3489309323@qq.com
 * @create 2020-09-18-19:14
 */
@Configuration
public class HttpSessionConfig {

  /**
   *  解决redis集群环境没有开启Keyspace notifications导致的
   *
   *  Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource
   *
   * */
  @Bean
  public static ConfigureRedisAction configureRedisAction() {
    return ConfigureRedisAction.NO_OP;
  }

  @Bean
  public CookieSerializer cookieSerializer(){
    DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

    cookieSerializer.setDomainName("mall.com");
    cookieSerializer.setCookieName("MALLSESSION");

    return cookieSerializer;
  }

  /** 名字必须叫 springSessionDefaultRedisSerializer 才有用*/
  @Bean
  public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
    return new GenericJackson2JsonRedisSerializer();
  }
}
